<?php
class Home extends Controller {
	
	function Home()
	{
	 error_reporting(0);
	 parent::Controller();
	 $this->load->model('Home_model');
	
	}
	
	function index()
	{
		//session_start();
		 if($this->session->userdata('buyerid') >0 )
		 {
		 $userid = $this->session->userdata('buyerid');
		 }elseif($this->session->userdata('sellerid') >0 )
		 {
		 $userid = $this->session->userdata('sellerid');
		 }
		 $data['productslist'] = $this->Product_model->getdoctypelist(); 
		 //print_r($productslist);
		 $current_user = $this->Product_model->getUserData($userid);
		 $data['listing']=$this->Product_model->homeproduct();		
		//print_r ($data['listing']);
		 $data['userdata'] = $current_user; 
        $data['catarr'] = $this->Home_model->categorylist();
		
		$this->load->view('layout/header',$data);
		if($this->session->userdata('buyerid') >0 ){
		$this->load->view('layout/leftsidebarbuyer_dashboard');
		}elseif($this->session->userdata('sellerid') >0 ){
		$this->load->view('layout/leftsidebar_dashboard');
		}else{		
			$this->load->view('layout/leftsidebar',$data);
		}
		$this->load->view('layout/homecontent',$data);
		$this->load->view('layout/footer');		
	}
	
	function dashboard()
	{
	    $this->load->view('layout/header');
		$this->load->view('layout/leftsidebar_dashboard');
		$this->load->view('layout/dashboard');
		$this->load->view('layout/footer');
	}
	
	function registration()
	{
	  
	    $data['country']=$this->Product_model->selcountry();
		$data['state']=$this->Product_model->selstate();
		$data['city']=$this->Product_model->selcity();
	    $this->load->view('layout/header');
		$this->load->view('layout/leftsidebar');
		$this->load->view('layout/userregistration_view',$data);
		$this->load->view('layout/footer');
		
	}
	function forgot()
   {
     $data="";
     if(isset($_POST['emailid']))
	 {
	  
	       $email=$_POST['emailid'];
		   
           $password=$this->Product_model->selpass($email);
		   
		   foreach($password as $key=>$value)
		   {
		    $pass= $value['password'];
		   }
	      
	      if($password[0]=="")
				{
				
				
				
				
				 $data['message']="EmailID doesnt exists ";
				
				}
				else
				{
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				$headers.= 'From: ProcessTalent' . "\n" .
						   'Reply-To: admin@ProcessTalent.com' . "\n" .
						   'Content-Transfer-Encoding: 8bit'."\n".
						   'X-Mailer: PHP/' . phpversion();
				$headers .= "X-Priority: 3\n";
				$subject="Forgot password Details for ProcessTalent.com";
				$message="<table class='reg-succ'  width='350' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#e35c00'>
							<tr><td>Your password:</td><td>".$pass."
							 </td></tr>
							 <tr>
							<td height=25 align=left valign=middle > Thank you,<br />
							  The ProcessTalent Team<br /></td>
							 </tr>
						</table>";
				$to=$email;
				mail($to, $subject, $message, $headers);
				
			    $data['message'] = 'mail sent successfully';
				$this->load->view('layout/header',$data);
				$this->load->view('layout/leftsidebar_dashboard');
				$this->load->view('layout/forgotpassword_view',$data);
				$this->load->view('layout/footer');
				}
				
	  
	   }
	   
	   
	
	           $this->load->view('layout/header',$data);
				$this->load->view('layout/leftsidebar_dashboard');
				$this->load->view('layout/forgotpassword_view',$data);
				$this->load->view('layout/footer');	
   }
   
	
	function logout()
	{
	 $this->session->sess_destroy();
     $this->session->sess_create('userid',0);
     redirect(REDIRECT_URL);
	}
	
	function buyerloginhome_action()
	{
	
	if(isset($_POST['usrname']) && isset($_POST['pwd'])){	
			
				$usrname = $_POST['usrname'];
				$password = $_POST['pwd'];
				//$password = md5($_POST['pwd']);
				
				 $user_id = $this->Product_model->checkbuyerLogin($usrname,$password);
                													
				if($user_id > 0 ) {
					$this->session->set_userdata("buyerid",$user_id);
					$this->session->set_userdata("sellerid",0);
					redirect(WEB_URL . 'buyer/home');
				

				}else{	
                     			
					$data['err_msg'] = "Invalid Username<br> or password"; 
					$this->load->view('layout/header',$data);
					$this->load->view('layout/leftsidebar');
		            $this->load->view('layout/buyerlogin_view',$data);
					$this->load->view('layout/footer');													
				}
			} else {
			
				//$data['linkarray'] = $this->home_model->querysiteLinks();
                
				$this->load->view('layout/header');
				$this->load->view('layout/leftsidebar');
		        $this->load->view('layout/homecontent');
				$this->load->view('layout/footer');														
			}
	    
	}
	function productimage()
	{
	            $userid = $this->session->userdata('userid');
				$current_user = $this->Product_model->getUserData($userid);
				$data['userdata'] = $current_user; 
	            $doc=$this->session->userdata('doctype');
				$category = $this->session->userdata('category');
				$subcategory = $this->session->userdata('subcategory');
				$process = $this->session->userdata('process');
				$doctype = $this->session->userdata('doctype');
				if(isset($_POST['adddesc']))
				{								
				$product=$_POST['product'];
				$productdesc=$_POST['productdesc'];
				$price=$_POST['price'];
				$tax1=$_POST['tax1'];
				$tax2=$_POST['tax2'];
				$disc=$_POST['disc'];
				$download=$_POST['download'];
				$filename = $_FILES['pfile']['name'];
				$uploaddir = ROOT_PATH.'images/'; 
				
				$dir = opendir($uploaddir);                                 
				$ext = end(explode(".", $filename));
				
				if($ext == "doc" || $ext =="pdf" ){
					$newfilename = rand(111111,999999) . "." . $ext ;			 
					$uploadfile = $uploaddir .$newfilename ;                                 
					move_uploaded_file($_FILES['pfile']['tmp_name'], $uploadfile);
					$data['message'] = " File Uploaded Successfully";
					
				}
				else{
					$data['message'] = " Invalid File type" ;
					$newfilename="nophoto.jpg";
					$inval=FALSE;	
				}
				if($_POST['product']!="" || $_POST['productdesc']!="" || $_POST['price']!="" || $_POST['tax1']!="" || $_POST['tax2']!="" )
				{
				$inval=$this->Product_model->adddescription($product,$productdesc,$newfilename,$disc,$price,$tax1,$tax2,$userid,$doc);
				
				$this->session->set_userdata('lastid',$inval);
				}
			
			
				}
		        $this->load->view('layout/header',$data);
				$this->load->view('layout/leftsidebar_dashboard');
				$this->load->view('layout/addvideo',$data);
				$this->load->view('layout/footer');
	
	}
	
	
	
	
	
	
	/*thamizh Added this*/

	function home_page()
	{		
		$this->load->view('layout/header');
		$this->load->view('layout/leftsidebar');
		$this->load->view('layout/homecontent');
		$this->load->view('layout/footer');

	}
    		
	/* End */
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */